//
//  ZH_MallOrderViewModel.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/11/6.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_MallOrderViewModel.h"
//订单详情接口
#define order_detail   @"/api/order/order_detail"
//用户订单支付页面请求
#define orderOrder     @"/api/order/order"
//新增收货地址
#define orderAdd_address     @"/api/order/add_address"
//我的订单
#define order_list           @"/api/order/order_list"
//获取商品列表
#define goods_list           @"/api/goods/goods_list"
//用户收货地址列表
#define orderAddress         @"/api/order/address"
//商城分类页面左侧大分类获取
#define goodsAll_cate        @"/api/goods/all_cate"
//商城首页推荐商品获取
#define goodsGroom_goods     @"/api/goods/groom_goods"
//商城首页轮播图获取
#define goodsBanner          @"/api/goods/banner"
//商城分类页面右侧二级三级分类获取
#define goodsCate_son        @"/api/goods/cate_son"
//商城首页分类请求
#define goods_cate           @"/api/goods/goods_cate"
//商城首页热销产品获取
#define hot_goods            @"/api/goods/hot_goods"
//商品详情请求
#define goods_detail         @"/api/goods/goods_detail"
//用户收货地址列表
#define address         @"/api/order/address"
@implementation ZH_MallOrderViewModel
//订单详情接口
- (void)orderDetailResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:order_detail dictionaryParam:self.orderDetailParam withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}

//用户订单支付页面请求
- (void)orderResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:orderOrder dictionaryParam:self.orderParam withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}

//新增收货地址
- (void)addAddressResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:orderAdd_address dictionaryParam:self.addAddressParam withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}

//我的订单
- (void)orderListResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:order_list dictionaryParam:self.orderListParam withResultBlock:^(NSString *code, NSString *message, id data) {
        
    }];
}

//获取商品列表
- (void)goodsListResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:goods_list dictionaryParam:self.goodsListParam withResultBlock:^(NSString *code, NSString *message, id data) {
        NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:0];
        if(![data[@"data"] isKindOfClass:[NSNull class]]){
            resultArray = data[@"data"][@"data"];
        }
        if(resultArray.count > 0){
            if([[self.goodsListParam objectForKey:@"page"] isEqualToString:@"1"]){
                [self.goodsListArray removeAllObjects];
            }
            [self.goodsListArray addObjectsFromArray:resultArray];
            if(resultBlock){
                resultBlock(code,message,self.goodsListArray);
            }
        }
        else{
            if(resultBlock){
                resultBlock(code, message, nil);
            }
        }

    }];
}

//用户收货地址列表
- (void)orderAddressResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:orderAddress dictionaryParam:self.orderAddressParam withResultBlock:^(NSString *code, NSString *message, id data) {
        
    }];
}

//商城分类页面左侧大分类获取
- (void)allCateResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:goodsAll_cate dictionaryParam:self.allCateParam withResultBlock:^(NSString *code, NSString *message, id data) {
        NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:0];
        if (![data[@"data"] isKindOfClass:[NSNull class]]) {
            resultArray = data[@"data"];
        }
        if(resultArray.count > 0){
            [self.allCateArray removeAllObjects];
            [self.allCateArray addObjectsFromArray:resultArray];
            if(resultBlock){
                resultBlock(code,message,data);
            }
        }
        else{
            if(resultBlock){
                resultBlock(code, message, nil);
            }
        }

    }];
}

//商城首页推荐商品获取
- (void)groomGoodsResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:goodsGroom_goods dictionaryParam:self.groomGoodsParam withResultBlock:^(NSString *code, NSString *message, id data) {
        NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:0];
        if (![data[@"data"] isKindOfClass:[NSNull class]]) {
            resultArray = data[@"data"][@"data"];
        }
        if(resultArray.count > 0){
            [self.groomGoodsArray removeAllObjects];
            [self.groomGoodsArray addObjectsFromArray:resultArray];
            if(resultBlock){
                resultBlock(code,message,data);
            }
        }
        else{
            if(resultBlock){
                resultBlock(code, message, nil);
            }
        }

    }];
}

//商城首页轮播图获取
- (void)goodsBannerResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:goodsBanner dictionaryParam:@{@"token":[DATAMODEL.configDBHelper getToken]} withResultBlock:^(NSString *code, NSString *message, id data) {
        NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:0];
        if (![data[@"data"] isKindOfClass:[NSNull class]]) {
            resultArray = data[@"data"];
        }
        if(resultArray.count > 0){
            [self.goodsBannerArray removeAllObjects];
            [self.goodsBannerArray addObjectsFromArray:resultArray];
            if(resultBlock){
                resultBlock(code,message,data);
            }
        }
        else{
            if(resultBlock){
                resultBlock(code, message, nil);
            }
        }

    }];
}

//商城分类页面右侧二级三级分类获取
- (void)cateSonResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:goodsCate_son dictionaryParam:self.cateSonParam withResultBlock:^(NSString *code, NSString *message, id data) {
        NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:0];
        if (![data[@"data"] isKindOfClass:[NSNull class]]) {
            resultArray = data[@"data"];
        }
        if(resultArray.count > 0){
            [self.cateSonArray removeAllObjects];
            [self.cateSonArray addObjectsFromArray:resultArray];
            if(resultBlock){
                resultBlock(code,message,data);
            }
        }
        else{
            if(resultBlock){
                resultBlock(code, message, nil);
            }
        }
    }];
}

//商城首页分类请求
- (void)goodsCateResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:goods_cate dictionaryParam:@{@"token":[DATAMODEL.configDBHelper getToken]} withResultBlock:^(NSString *code, NSString *message, id data) {
        NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:0];
        if (![data[@"data"] isKindOfClass:[NSNull class]]) {
            resultArray = data[@"data"];

        }
        if(resultArray.count > 0){
            [self.goodsCateArray removeAllObjects];
            [self.goodsCateArray addObjectsFromArray:resultArray];
            if(resultBlock){
                resultBlock(code,message,data);
            }
        }
        else{
            if(resultBlock){
                resultBlock(code, message, nil);
            }
        }
    }];
}

//商城首页热销产品获取
- (void)hotGoodsResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:hot_goods dictionaryParam:@{@"token":[DATAMODEL.configDBHelper getToken]} withResultBlock:^(NSString *code, NSString *message, id data) {
        NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:0];
        if (![data[@"data"] isKindOfClass:[NSNull class]]) {
             resultArray = data[@"data"];
        }
        if(resultArray.count > 0){
            [self.hotGoodsArray removeAllObjects];
            [self.hotGoodsArray addObjectsFromArray:resultArray];
            if(resultBlock){
                resultBlock(code,message,data);
            }
        }
        else{
            if(resultBlock){
                resultBlock(code, message, nil);
            }
        }
    }];
}

//商品详情请求
- (void)goodsDetailResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:goods_detail dictionaryParam:self.goodsDetailParam withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}
//用户收货地址列表
- (void)addressResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:address dictionaryParam:nil withResultBlock:^(NSString *code, NSString *message, id data) {
        
    }];
}
#pragma mark - getter,setter
//订单详情接口
- (NSMutableDictionary *)orderDetailParam{
    if (!_orderDetailParam) {
        _orderDetailParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_orderDetailParam setObject:@"" forKey:@"token"];
        [_orderDetailParam setObject:@"" forKey:@"id"];
    }
    return _orderDetailParam;
}

//用户订单支付页面请求
- (NSMutableDictionary *)orderParam{
    if (!_orderParam) {
        _orderParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_orderParam setObject:@"" forKey:@"token"];
        [_orderParam setObject:@"" forKey:@"id"];
        [_orderParam setObject:@"" forKey:@"address"];
        [_orderParam setObject:@"" forKey:@"order_id"];
    }
    return _orderParam;
}

//新增收货地址
- (NSMutableDictionary *)addAddressParam{
    if (!_addAddressParam) {
        _addAddressParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_addAddressParam setObject:@"" forKey:@"token"];
        [_addAddressParam setObject:@"" forKey:@"phone"];
        [_addAddressParam setObject:@"" forKey:@"name"];
        [_addAddressParam setObject:@"" forKey:@"province"];
        [_addAddressParam setObject:@"" forKey:@"city"];
        [_addAddressParam setObject:@"" forKey:@"address"];
        [_addAddressParam setObject:@"" forKey:@"area"];
    }
    return _addAddressParam;
}

//我的订单
- (NSMutableDictionary *)orderListParam{
    if (!_orderListParam) {
        _orderListParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_orderListParam setObject:@"" forKey:@"token"];
        [_orderListParam setObject:@"" forKey:@"status"];
    }
    return _orderListParam;
}
- (NSMutableArray *)orderListArray{
    if (!_orderListArray) {
        _orderListArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _orderListArray;
}

//获取商品列表
- (NSMutableDictionary *)goodsListParam{
    if (!_goodsListParam) {
        _goodsListParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_goodsListParam setObject:[DATAMODEL.configDBHelper getToken] forKey:@"token"];
        [_goodsListParam setObject:@"" forKey:@"id"];
        [_goodsListParam setObject:@"" forKey:@"money"];
        [_goodsListParam setObject:@"" forKey:@"page"];
    }
    return _goodsListParam;
}
- (NSMutableArray *)goodsListArray{
    if (!_goodsListArray) {
        _goodsListArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _goodsListArray;
}

//用户收货地址列表
- (NSMutableDictionary *)orderAddressParam{
    if (!_orderAddressParam) {
        _orderAddressParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_orderAddressParam setObject:@"" forKey:@"token"];
    }
    return _orderAddressParam;
}
- (NSMutableArray *)orderAddressArray{
    if (!_orderAddressArray) {
        _orderAddressArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _orderAddressArray;
}

//商城分类页面左侧大分类获取
- (NSMutableDictionary *)allCateParam{
    if (!_allCateParam) {
        _allCateParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_allCateParam setObject:[DATAMODEL.configDBHelper getToken] forKey:@"token"];
    }
    return _allCateParam;
}
- (NSMutableArray *)allCateArray{
    if (!_allCateArray) {
        _allCateArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _allCateArray;
}

//商城首页推荐商品获取
- (NSMutableDictionary *)groomGoodsParam{
    if (!_groomGoodsParam) {
        _groomGoodsParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_groomGoodsParam setObject:[DATAMODEL.configDBHelper getToken] forKey:@"token"];
        [_groomGoodsParam setObject:@"" forKey:@"page"];
    }
    return _groomGoodsParam;
}
- (NSMutableArray *)groomGoodsArray{
    if (!_groomGoodsArray) {
        _groomGoodsArray = [[NSMutableArray alloc] init];
    }
    return _groomGoodsArray;
}

//商城首页轮播图获取
- (NSMutableArray *)goodsBannerArray{
    if (!_goodsBannerArray) {
        _goodsBannerArray = [[NSMutableArray alloc] init];
    }
    return _goodsBannerArray;
}

//商城分类页面右侧二级三级分类获取
- (NSMutableDictionary *)cateSonParam{
    if (!_cateSonParam) {
        _cateSonParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_cateSonParam setObject:[DATAMODEL.configDBHelper getToken] forKey:@"token"];
        [_cateSonParam setObject:@"" forKey:@"id"];
    }
    return _cateSonParam;
}
- (NSMutableArray *)cateSonArray{
    if (!_cateSonArray) {
        _cateSonArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _cateSonArray;
}
//商城首页分类请求
- (NSMutableArray *)goodsCateArray{
    if (!_goodsCateArray) {
        _goodsCateArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _goodsCateArray;
}
//商城首页热销产品获取
- (NSMutableArray *)hotGoodsArray{
    if (!_hotGoodsArray) {
        _hotGoodsArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _hotGoodsArray;
}

//商品详情请求
- (NSMutableDictionary *)goodsDetailParam{
    if (!_goodsDetailParam) {
        _goodsDetailParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_goodsDetailParam setObject:[DATAMODEL.configDBHelper getToken] forKey:@"token"];
        [_goodsDetailParam setObject:@"" forKey:@"id"];
    }
    return _goodsDetailParam;
}

//用户收货地址列表
- (NSMutableArray *)addressArray{
    if (!_addressArray) {
        _addressArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _addressArray;
}
@end
